package com.qf.contorller;

import com.qf.service.SearchService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * author:z
 * time:2022/1/3 21:53
 * description:
 */

@RestController
@RequestMapping("/search")
public class Controller {

    @Resource
    SearchService searchService;

    @RequestMapping(value = "/search", method = RequestMethod.POST)
    List<Map> searchLog(@RequestParam("params") String paras) {
        return searchService.searchLog(paras);
    }

    @RequestMapping(value = "/searchcount", method = RequestMethod.POST)
    Long searchLogCount(@RequestParam("params") String paras) {
        //遍历日志中的总数
        List<Map> maps = searchService.searchLog(paras);
        for (Map map : maps) {
            if (map.get("count") != null) {
                return (Long) map.get("count");
            }
        }
        return null;
    }
}
